from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
from itsdangerous import BadSignature

def generic_verify_url(user_id,email):

    #1.创建序列化器
    serializer = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    #2.组织数据
    data = {
        'user_id':user_id,
        'email':email
    }
    #3.进行加密处理
    token = serializer.dumps(data)
    #4. 返回
    return 'http://www.meiduo.site:8080/success_verify_email.html?token=%s'%token.decode()

def check_active_token(token):


    serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)

    try:
        data = serializer.loads(token)
    except BadSignature:
        return None

    return data
